home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr10 / v12n12.zip / PCMCVT.ZIP / PCMASM.ZIP / WP51CONV.INC < prev    next >
Text File  |  1993-05-29  |  7KB  |  235 lines

  1. ;WP51CONV.INC
  2. ;Copyright (c) 1993 Jay Munro
  3. ;First Published in PC Magazine June 29 1993
  4. ;PCMCVT Conversion module for WordPerfect 5.1, 5.2
  5. ;final
  6. WordPerfectCVT Proc Near
  7.  
  8. ReadWPFile:
  9.     Lea    SI,HeaderBuffer
  10.     Invoke Seek,SHandle,[SI].WPDocStart ;go to start of text
  11.     Call   WP51ReadIt                   ;go read the file
  12.     Jnc    RWPLoop
  13.     Jmp    WP51Exit
  14.  
  15. RWPLoop:
  16.     LodSb                               ;grab a character
  17.     Cmp    AL,13                        ;a soft return?
  18.     Jnz    @F
  19.     Cmp    Byte Ptr WordWrapFlag,-1     ;are we doing word wrap?
  20.     Jz     RepWSpace                    ;yes, then just test for a space
  21.     Mov    AL,10                        ;no, put in a linefeed to preserve
  22.     Jmp    @F                           ;   original formatting
  23.  
  24. RepWSpace:
  25.     Cmp    SI,TopEnd                    ;can we look ahead?
  26.     Jnz    Ret2Space
  27.     Call   WP51ReadIt
  28.     Jnc    Ret2Space
  29.     Jmp    WP51Exit
  30.  
  31. Ret2Space:
  32.     Cmp    Byte Ptr [SI],32   ;[+1]     ;is the next character a space?
  33.     Jz     @F                           ;yes, then we don't need to include it.
  34.     Mov    AL,32                        ;replace the character with a space
  35.     Call   WriteIt
  36.     Jmp    ReLoop                       ;skip over
  37.     
  38. @@:
  39.     Cmp    AL,10                        ;hard cr for WP
  40.     Jnz    @F
  41.     Mov    AL,13
  42.     Call   WriteIt                      ;write what's in AL
  43.     Mov    AL,10                        ;make it a hard return
  44.     Call   WriteIt
  45.     Jmp    ReLoop
  46.  
  47. @@:
  48.     Cmp    AL,0A9h                      ;hard hyphen
  49.     Jnz    @F
  50.     Mov    AL,'-'
  51.     Call   WriteIt                      ;write it
  52.     Jmp    ReLoop     
  53. @@:
  54.     Cmp    AL,0AAh                      ;hard hyphen at end of line
  55.     Jnz    @F
  56.     Mov    AL,'-'
  57.     Call   WriteIt                      ;write it
  58.     Jmp    ReLoop 
  59. @@:
  60.     Cmp    AL,0ABh                      ;hard hyphen at end of page
  61.     Jnz    @F
  62.     Mov    AL,'-'
  63.     Call   WriteIt                      ;write it
  64.     Jmp    ReLoop
  65.  
  66. @@:
  67.     Cmp    AL,0A0h                      ;hard space
  68.     Jnz    @F                           
  69.     Mov    AL,32
  70.     Call   WriteIt                      ;write it
  71.     Jmp    ReLoop
  72.  
  73. @@:                                     ;tabs
  74.     Cmp    AL,0C1h                      ;code for tabs
  75.     Jnz    SoftReturn
  76.  
  77. WPTabLoop:
  78.     Cmp   SI,TopEnd
  79.     Jz    WPTabReRead
  80.     LodSb                               ;grab the next character
  81.     And    AL,1100000b
  82.     Jnz    NoTab
  83.     Call   DoTabs                       ;expand the tabs
  84.     
  85. NoTab:
  86.     Cmp    SI,TopEnd                    ;hit the end of the read buffer?
  87.     Jnz    WPTabOk                      ;no, continue
  88.     Push   AX                           ;else preserve AX and reread
  89.     Call   WP51ReadIt                   ;a piece of the file
  90.     Pop    AX                           ;retrieve AX
  91.     Jc     WPExitLeap                   ;if file error, exit peacefully
  92.     
  93. WPTabOk:
  94.     LodSb
  95.     Cmp    AL,0C1h                      ;is it the end function code?
  96.     Jnz    NoTab
  97.     Jmp    ReLoop
  98.  
  99. WPTabReRead:
  100.     Push   AX
  101.     Call   WP51ReadIt
  102.     Pop    AX
  103.     Jc     WPExitLeap
  104.     Jmp    WPTabLoop
  105.  
  106. SoftReturn:
  107.     Cmp    AL,13                        ;soft return?  (*in for future ref*)
  108.     Jz     ReLoopLeap                   ;skip it
  109.     Cmp    AL,1Fh                       ;is it a control char?
  110.     Jbe    ReLoopLeap                   ;skip it
  111.  
  112.     Cmp    AL,80h                       ;start of single byte function
  113.     Jb     @F
  114.     Jmp    Short FunctionCheck          ;check function
  115.     
  116. @@:
  117.     Call   WriteIt                      ;no, then write it
  118.  
  119. ReLoopLeap:                             ;leap frog to avoid warning errors
  120.     Jmp    ReLoop
  121.  
  122. WPExitLeap:
  123.     Jmp    Wp51Exit                     ;leap frog to avoid warning errors
  124.     
  125. FunctionCheck:                          ;Single character control codes
  126.     Cmp    AL,0BFh                      ;is it single or multibyte
  127.     Jbe    ReLoopLeap
  128.  
  129.     Cmp    AL,0D0h                      ;variable length multibyte
  130.     Jae    MultiByte
  131.     Mov    AH,AL                        ;save the function code (0Cx) into AH
  132.     
  133. FixedLenMB:                             ;fixed length multibyte
  134.     LodSb                               ;get a byte
  135.     Cmp    AH,AL                        ;did we get to the end of the function
  136.     Jz     ReLoop                       ;yes, then exit and continue
  137.     Cmp    Word Ptr SI,TopEnd
  138.     Jz     FLMBReread
  139.     Jmp    FixedLenMB
  140.  
  141. FLMBReread:
  142.     Push   AX                           ;ran out of buffer, read more from file
  143.     Call   WP51ReadIt                   ;read file
  144.     Pop    AX                           ;retrieve character (AH is of interest)
  145.     Jc     Wp51Exit                     ;exit out if no more character (error)
  146.     Jmp    FixedLenMB                   ;go back for more
  147.  
  148. MultiByte:
  149.     Cmp    AL,0DCh                      ;is it a column ?
  150.     Jz     ColumnCode                   ;yes
  151.     Cmp    AL,0D4h                      ;how about a soft or hard page
  152.     Jnz    ByteLoop                     ;no, continue
  153.  
  154.     Cmp    SI,TopEnd                    ;can we look ahead?
  155.     Jnz    @F                           ;yes, then do it
  156.     Call   WP51ReadIt
  157.     Jc     WPExitLeap
  158.  
  159. @@:
  160.     Cmp    Byte Ptr [SI],0              ;ok, service 0 ?
  161.     Jnz    ByteLoop                     ;not service 0, skip ahead
  162.     Mov    AL,12                        ;write page feed
  163.     Call   WriteIt                      ;
  164.     Jmp    ByteLoop                     ;
  165.     
  166. ColumnCode:
  167.     Cmp    SI,TopEnd                    ;can we look ahead?
  168.     Jnz    @F                           ;yes, then do it
  169.     Call   WP51ReadIt
  170.     Jc     WPExitLeap
  171.  
  172. @@:
  173.     Cmp    Byte Ptr [SI],0              ;ok, service 0 ?
  174.     Jnz    ByteLoop                     ;not service 0, skip ahead
  175.     Mov    AL,13
  176.     Call   WriteIt
  177.     Mov    AL,10
  178.     Call   WriteIt
  179.  
  180. ByteLoop:
  181.     Inc    SI                           ;move up a character
  182.     Cmp    SI,TopEnd                    ;did we get to the last byte?
  183.     Jnz    @F                           ;re-read file
  184.     Call   WP51ReadIt
  185.     Jc     WPExitLeap
  186.     
  187. @@:
  188.     Mov    DX,[SI]
  189.     Add    DX,2                         ;add difference
  190.  
  191. ByteLoop2:
  192.     Inc    SI                   ;point to next character
  193.     Cmp    SI,TopEnd            ;time to read more?
  194.     Jg     @F                   ;yes, go read
  195.  
  196. ReByte2:
  197.     Dec    DX                   ;count inner loop
  198.     Jz     ReLoop               ;go back when done
  199.     Jmp    ByteLoop2
  200.  
  201. @@:
  202.     Call   WP51ReadIt
  203.     Jc     @F
  204.     Jmp     ByteLoop2
  205.     
  206. @@:
  207.     Jmp    WP51Exit
  208.  
  209. ReLoop:
  210.     Cmp    Word Ptr SI,TopEnd
  211.     Jz     @F
  212.     Jmp    RWPLeap
  213. @@:
  214.     Call WP51ReadIt
  215.     Jc   Wp51Exit
  216.  
  217. RWPLeap:
  218.     Jmp  RWPLoop
  219.  
  220. WP51Exit:
  221.     Ret
  222.  
  223. WP51ReadIt:
  224.     Push   DX                           ;save function loop counter
  225.     Call   ReadIt                       ;go read the file
  226.     Jnc    @F
  227.     Mov    AL,-1                        ;flush buffer
  228.     Call   WriteIt                      ;clear it
  229.     Stc
  230. @@:
  231.     Pop    DX
  232.     RetN
  233.  
  234. WordPerfectCVT EndP
  235.